<?php

/*
=====================================================
 FluxBB - Delux Board Converstations (DBC)
-----------------------------------------------------
 http://dbc-forum.com/
 http://fluxbb.org/
-----------------------------------------------------
 Copyright (c) 2010,2011 FluxBB - Delux Board Conversations (DBC)
-----------------------------------------------------
 Предсловие: Данный скрипт (DBC) не является работой с нуля, то 
 есть ядром скрипта всё также остаётся FuxBB,но теперь в оболочке
 DBC.
=====================================================
*/

// Make sure no one attempts to run this script "directly"
if (!defined('DBC'))
	exit;
if (isset($_GET['ajax']))
	return;
	
$basenameSelf = basename($_SERVER['PHP_SELF']);

// Send no-cache headers
header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); 
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache'); // For HTTP/1.0 compatibility

// Send the Content-type header in case the web server is setup to send something else
header('Content-type: text/html; charset=utf-8');

// Load the template
if (defined('DBC_ADMIN_CONSOLE'))
	$tpl_file = 'admin.tpl';
else if (defined('DBC_HELP'))
	$tpl_file = 'help.tpl';
else if (defined('DBC_PROFILE'))
	$tpl_file = 'profile.tpl';
else if (defined('DBC_LOGIN'))
	$tpl_file = 'login.tpl';
else if (defined('DBC_REPUTATION'))
	$tpl_file = 'reputation.tpl';
else if (defined('DBC_REDIRECT'))
	$tpl_file = 're.tpl';
else if (defined('DBC_VIEWFORUM'))
	$tpl_file = 'viewforum.tpl';
else if (defined('DBC_VIEWTOPIC'))
	$tpl_file = 'viewtopic.tpl';
else if (defined('DBC_POST'))
	$tpl_file = 'post.tpl';
else if (defined('DBC_DELETE'))
	$tpl_file = 'delete.tpl';
else if (defined('DBC_INFO'))
	$tpl_file = 'info.tpl';
else if (defined('DBC_LOST_PASSWORD'))
	$tpl_file = 'lostpassword.tpl';
else if (defined('DBC_CHANGE_PASSWORD'))
	$tpl_file = 'changepass.tpl';
else if (defined('DBC_REGISTR'))
	$tpl_file = 'registration.tpl';
else if (defined('DBC_STATIC'))
	$tpl_file = 'static.tpl';
else if (defined('DBC_SEARCH'))
	$tpl_file = 'search.tpl';
else if (defined('DBC_USERS'))
	$tpl_file = 'users.tpl';
else if (defined('DBC_PM'))
	$tpl_file = 'pm.tpl';
else if (defined('DBC_MODERATE'))
	$tpl_file = 'moderate.tpl';
else if (defined('DBC_EDIT'))
	$tpl_file = 'edit.tpl';
else if (defined('DBC_STATS'))
	$tpl_file = 'stats.tpl';
else
	$tpl_file = 'main.tpl';

if (file_exists(DBC_ROOT.'templates/'.$DBC_user['style'].'/'.$tpl_file))
{
	$tpl_file = DBC_ROOT.'templates/'.$DBC_user['style'].'/'.$tpl_file;
	$tpl_inc_dir = DBC_ROOT.'templates/'.$DBC_user['style'].'/';
}
else
{
	$tpl_file = DBC_ROOT.'templates/'.$DBC_user['style'].'/'.$tpl_file;
	$tpl_inc_dir = DBC_ROOT.'templates/'.$DBC_user['style'].'/';
}

$tpl_main = file_get_contents($tpl_file);

// START SUBST - <DBC_include "*">
preg_match_all('#<DBC_include "([^/\\\\]*?)\.(php[45]?|inc|html?|txt)">#', $tpl_main, $DBC_includes, PREG_SET_ORDER);

foreach ($DBC_includes as $cur_include)
{
	ob_start();

	// Allow for overriding user includes, too.
	if (file_exists($tpl_inc_dir.$cur_include[1].'.'.$cur_include[2]))
		require $tpl_inc_dir.$cur_include[1].'.'.$cur_include[2];
	else if (file_exists(DBC_ROOT.'engine/user/'.$cur_include[1].'.'.$cur_include[2]))
		require DBC_ROOT.'engine/user/'.$cur_include[1].'.'.$cur_include[2];
	else
		error(sprintf($lang_common['DBC include error'], htmlspecialchars($cur_include[0]), basename($tpl_file)));

	$tpl_temp = ob_get_contents();
	$tpl_main = str_replace($cur_include[0], $tpl_temp, $tpl_main);
	ob_end_clean();
}
// END SUBST - <DBC_include "*">

// START SUBST - {DBC_language}
$tpl_main = str_replace('{DBC_language}', $lang_common['lang_identifier'], $tpl_main);
// END SUBST - {DBC_language}

// Tags forums table

// START SUBST - {DBC_content_direction}
$tpl_main = str_replace('{DBC_content_direction}', $lang_common['lang_direction'], $tpl_main);
// END SUBST - {DBC_content_direction}

// START SUBST - {search}
$tpl_main = str_replace('{search}', $lang_common['msearch'], $tpl_main);
// END SUBST - {search}


// START SUBST - {Social links}
$tpl_main = str_replace('{vk_link}', ''.($DBC_config['o_vk_link']).'', $tpl_main);
$tpl_main = str_replace('{fb_link}', ''.($DBC_config['o_fb_link']).'', $tpl_main);
$tpl_main = str_replace('{wm_link}', ''.($DBC_config['o_wm_link']).'', $tpl_main);
// END SUBST -  {Social links}

// START SUBST - {THEME}
$tpl_main = str_replace('{THEME}', ''.($DBC_config['o_base_url']).'/templates/'.($DBC_user['style']).'', $tpl_main);
// END SUBST - {THEME}

// START SUBST
$tpl_main = str_replace('{HOME_LINK}', ''.($DBC_config['o_base_url']).'', $tpl_main);
// END SUBST

// START SUBST - {DBC_head}
ob_start();

// Define $p if its not set to avoid a PHP notice
$p = isset($p) ? $p : null;

// Is this a page that we want search index spiders to index?
if (!defined('DBC_ALLOW_INDEX'))
	echo '<meta name="ROBOTS" content="NOINDEX, FOLLOW" />'."\n";

?>
<title><?php echo generate_page_title($page_title, $p) ?></title>
<link rel="shortcut icon" href="<?php echo $DBC_config['o_base_url'] ?>/favicon.ico" />
<script type="text/javascript" src="<?php echo $DBC_config['o_base_url'] ?>/engine/classes/js/jquery.js"></script>
<script type="text/javascript" src="<?php echo $DBC_config['o_base_url'] ?>/engine/classes/js/jqueryui.js"></script>
<script type="text/javascript" src="<?php echo $DBC_config['o_base_url'] ?>/engine/classes/js/dbc_js.js"></script>
<script type="text/javascript" src="<?php echo $DBC_config['o_base_url'] ?>/engine/classes/js/tooltip.js"></script>

<script>
$(document).ready(function(){$("a").easyTooltip()});$(document).ready(function(){$("img").easyTooltip()});
</script>

<script type="text/javascript" src="<?php echo $DBC_config['o_base_url'] ?>/engine/classes/js/autoresize-mod.jquery.js"></script>

<script type="text/javascript">
		jQuery('textarea').autoResize({
		 	// On resize:
			onResize : function() {
				jQuery(this);
			},
			// After resize:
			animateCallback : function() {
				jQuery(this);
			}
		});
</script>

<script language="javascript" type="text/javascript">
<!--
var dbc_root       = '<?php echo $DBC_config['o_base_url'] ?>';
//-->
</script>
<?php
if (isset($required_fields))
{
	// Output JavaScript to validate form (make sure required fields are filled out)

?>
<script type="text/javascript">
/* <![CDATA[ */
function process_form(the_form)
{
	var element_names = new Object()
<?php

	// Output a JavaScript array with localised field names
	foreach ($required_fields as $elem_orig => $elem_trans)
		echo "\t".'element_names["'.$elem_orig.'"] = "'.addslashes(str_replace('&#160;', ' ', $elem_trans)).'"'."\n";

?>

	if (document.all || document.getElementById)
	{
		for (var i = 0; i < the_form.length; ++i)
		{
			var elem = the_form.elements[i]
			if (elem.name && elem.name.substring(0, 4) == "req_")
			{
				if (elem.type && (elem.type=="text" || elem.type=="textarea" || elem.type=="password" || elem.type=="file") && elem.value=='')
				{
					alert("\"" + element_names[elem.name] + "\" <?php echo $lang_common['required field'] ?>")
					elem.focus()
					return false
				}
			}
		}
	}

	return true
}
/* ]]> */
</script>
<?php

}
// JavaScript tricks for IE6 and older
echo '<!--[if lte IE 6]><script type="text/javascript" src="'.$DBC_config['o_base_url'].'/engine/classes/js/minmax.js"></script><![endif]-->'."\n";
require DBC_ROOT.'engine/modules/pms_new/pmsnheader.php';
if (basename($_SERVER['PHP_SELF']) == 'viewtopic.php')
{	
	if (file_exists(DBC_ROOT.'language/'.$DBC_user['language'].'/topic.php'))
		require DBC_ROOT.'language/'.$DBC_user['language'].'/topic.php';
	else
		require DBC_ROOT.'language/English/topic.php';
	
	$ape = 'var base_url = \''.$DBC_config['o_base_url'].'\';';
	$ape .= "\n".'var ape = {\'Loading\' : \''.$lang_common['Ajax loading'].'\'';
	$ape .= ', \'Quick edit\' : \''.$lang_topic['Quick Edit'].'\'';
	$ape .= ', \'Full edit\' : \''.$lang_topic['Full Edit'].'\'';
	$ape .= ', \'Cancel edit confirm\' : \''.$lang_topic['Cancel edit confirm'].'\'';
	$ape .= '}';
	
	$page_head['ape'] = '<script type="text/javascript">'."\n".$ape."\n".'</script>';
	$page_head['ape_js'] = '<script type="text/javascript" src="'.$DBC_config['o_base_url'].'/engine/classes/js/post_edit.js"></script>';
	$page_head['ape_css'] = '<link rel="stylesheet" type="text/css" href="'.$DBC_config['o_base_url'].'/engine/skins/style/style.css" />';
}

if (isset($page_head))
	global $DBC_colorize_groups; // need this for message function
	$page_head['colorize_groups'] = '<style type="text/css">'.$DBC_colorize_groups['style'].'</style>';
	echo implode("\n", $page_head)."\n";

$tpl_temp = trim(ob_get_contents());
$tpl_main = str_replace('{headers}', $tpl_temp, $tpl_main);
ob_end_clean();
// END SUBST - {DBC_head}

// START SUBST - <body>
if (isset($focus_element))
{
	$tpl_main = str_replace('<body onload="', '<body onload="document.getElementById(\''.$focus_element[0].'\').elements[\''.$focus_element[1].'\'].focus();', $tpl_main);
	$tpl_main = str_replace('<body>', '<body onload="document.getElementById(\''.$focus_element[0].'\').elements[\''.$focus_element[1].'\'].focus()">', $tpl_main);
}
// END SUBST - <body>

// START SUBST - {DBC_page}
$tpl_main = str_replace('{DBC_page}', htmlspecialchars(basename($_SERVER['PHP_SELF'], '.php')), $tpl_main);
// END SUBST - {DBC_page}


// START SUBST - {dbc_name}
$tpl_main = str_replace('{dbc_name}', '<span class="dbc_title">'.DBC_htmlspecialchars($DBC_config['o_board_title']).'</span>', $tpl_main);
// END SUBST - {dbc_name}

// START SUBST - {dbc_name}
$tpl_main = str_replace('{poster_id}', ''.$cur_post['poster_id'].'', $tpl_main);
// END SUBST - {dbc_name}

// START SUBST - {DBC_desc}
$tpl_main = str_replace('{DBC_desc}', '<div id="brddesc">'.$DBC_config['o_board_desc'].'</div>', $tpl_main);
// END SUBST - {DBC_desc}

// START SUBST - {navigation}
$tpl_main = str_replace('{navigation}','<div class="bottmenu">'."\n\t\t\t". generate_navlinks()."\n\t\t".'</div>', $tpl_main);
// END SUBST - {navigation}

// START SUBST - {navigation_r}
$tpl_main = str_replace('{navigation_r}','<div class="bottmenu">'."\n\t\t\t". generate_links_friends()."\n\t\t".'</div>', $tpl_main);
// END SUBST - {navigation_r}
if ($DBC_user['is_guest']) // No Avatar для гостя
    $tpl_temp = '<img src="'.$DBC_config['o_base_url'].'/templates/'.$DBC_user['style'].'/images/noavatar.png" width="100" height="100" alt="" />';
else // Аватар для пользователя
{
    $tpl_temp = generate_avatar_markup($DBC_user['id']);
}

$tpl_main = str_replace('{avatar}', $tpl_temp, $tpl_main);

// START SUBST - {ajax}
$tpl_main = str_replace('{ajax}','<div id="aqp-icon" style="display:none"><div id="aqp-icon-middle"><div id="aqp-icon-text">'.$lang_common['Ajax loading'].'</div></div></div>', $tpl_main);
// END SUBST - {ajax}

// START SUBST - {DBC_status}
if ($DBC_user['is_guest'])
	$tpl_temp = '<div id="brdwelcome" class="inbox">'."\n\t\t\t".'<p>'.$lang_common['Not logged in'].'</p>'."\n\t\t".'</div>';
else
{
	$tpl_temp = '<div id="brdwelcome" class="inbox">'."\n\t\t\t".'<ul class="conl">'."\n\t\t\t\t".'<li><span>'.$lang_common['Logged in as'].' <strong>'.DBC_htmlspecialchars($DBC_user['username']).'</strong></span></li>'."\n\t\t\t\t".'<li><span>'.sprintf($lang_common['Last visit'], format_time($DBC_user['last_visit'])).'</span></li>';

	if ($DBC_user['is_admmod'])
	{
		if ($DBC_config['o_report_method'] == '0' || $DBC_config['o_report_method'] == '2')
		{
			$result_header = $db->query('SELECT 1 FROM '.$db->prefix.'reports WHERE zapped IS NULL') or error('Unable to fetch reports info', __FILE__, __LINE__, $db->error());

			if ($db->result($result_header))
				$tpl_temp .= "\n\t\t\t\t".'<li class="reportlink"><span><strong><a href="admin_reports.php">'.$lang_common['New reports'].'</a></strong></span></li>';
		}

		if ($DBC_config['o_maintenance'] == '1')
			$tpl_temp .= "\n\t\t\t\t".'<li class="maintenancelink"><span><strong><a href="admin_options.php#maintenance">'.$lang_common['Maintenance mode enabled'].'</a></strong></span></li>';
	}

	if (in_array($basenameSelf, array('index.php', 'search.php')))
		$tpl_temp .= "\n\t\t\t".'</ul>'."\n\t\t\t".'<ul class="conr">'.($DBC_user['g_search'] == '1' ? "\n\t\t\t\t".'<li><span><a href="new_posts">'.$lang_common['Show new posts'].'</a></span></li>' : '')."\n\t\t\t\t".'<li><span><a href="read_all">'.$lang_common['Mark all as read'].'</a></span></li>'."\n\t\t\t".'</ul>'."\n\t\t\t".'<div class="clearer"></div>'."\n\t\t".'</div>';
	else if ($basenameSelf == 'viewforum.php')
		$tpl_temp .= "\n\t\t\t".'</ul>'."\n\t\t\t".'<ul class="conr">'."\n\t\t\t\t".'<li><span><a href="misc.php?action=markforumread&amp;fid='.$id.'">'.$lang_common['Mark forum read'].'</a></span></li>'."\n\t\t\t".'</ul>'."\n\t\t\t".'<div class="clearer"></div>'."\n\t\t".'</div>';
	else
		$tpl_temp .= "\n\t\t\t".'</ul>'."\n\t\t\t".'<div class="clearer"></div>'."\n\t\t".'</div>';
}

$tpl_main = str_replace('{DBC_status}', $tpl_temp, $tpl_main, $tpl_login);
// END SUBST - {DBC_status}


// START SUBST - {mark_read}
if ($DBC_user['is_guest'])
	$tpl_temp = ''."\n\t\t\t".''."\n\t\t".'';
else
{
	$tpl_temp = ''."\n\t\t\t".''."\n\t\t\t\t".'<span><a href="read_all">'.$lang_common['Mark all as read'].'</a></span>'."\n\t\t\t\t".'';
}

$tpl_main = str_replace('{mark_read}', $tpl_temp, $tpl_main, $tpl_login);
// END SUBST - {mark_read}

if ($DBC_user['is_guest']) // No Avatar для гостя
    $tpl_temp = '<img src="'.$DBC_config['o_base_url'].'/templates/'.$DBC_user['style'].'/images/noavatar.png" width="100" height="100" alt="" />';
else // Аватар для пользователя
{
    $tpl_temp = generate_avatar_markup($DBC_user['id']);
}

$tpl_main = str_replace('{avatar}', $tpl_temp, $tpl_main);

// START SUBST - {new_posts}
if ($DBC_user['is_guest'])
	$tpl_temp = ''."\n\t\t\t".'<p>'.$lang_common['Not logged'].'</p>'."\n\t\t".'';
else
{
	$tpl_temp = ''."\n\t\t\t".''."\n\t\t\t\t".'<span><a href="new_posts">'.$lang_common['Show new posts'].'</a></span> |'."\n\t\t\t\t".'';
}

$tpl_main = str_replace('{new_posts}', $tpl_temp, $tpl_main, $tpl_login);
// END SUBST - {new_posts}

// START SUBST - {username}
if ($DBC_user['is_guest'])
	$tpl_temp = '<div id="brdwelcome" class="inbox">'."\n\t\t\t".'<p>'.$lang_common['Not logged in'].'</p>'."\n\t\t".'</div>';
else
{
	$tpl_temp = ''."\n\t\t\t".''."\n\t\t\t\t".'<span><strong>'.$lang_common['Logged in as'].' <span style="color: #01669A;"><a href="{profile-link}">'.DBC_htmlspecialchars($DBC_user['username']).'</a></span></strong></span>'."\n\t\t\t\t".'';
}

$tpl_main = str_replace('{username}', $tpl_temp, $tpl_main, $tpl_login);
// END SUBST - {username}

if ($DBC_user['is_guest'])
	$tpl_temp = '<div id="brdwelcome" class="inbox">'."\n\t\t\t".'<p>'.$lang_common['Not logged in'].'</p>'."\n\t\t".'</div>';
else
{
	$tpl_temp = ''."\n\t\t\t".''."\n\t\t\t\t".''.DBC_htmlspecialchars($DBC_user['username']).''."\n\t\t\t\t".'';
}

$tpl_main = str_replace('{login}', $tpl_temp, $tpl_main, $tpl_login);
// END SUBST - {login}

if ($DBC_user['is_guest'])
	$tpl_temp = '<div id="brdwelcome" class="inbox">'."\n\t\t\t".'<p>'.$lang_common['Not logged in'].'</p>'."\n\t\t".'</div>';
else
{
	$tpl_temp = ''."\n\t\t\t".''."\n\t\t\t\t".'pm'."\n\t\t\t\t".'';
}

$tpl_main = str_replace('{pm-link}', $tpl_temp, $tpl_main, $tpl_login);
// END SUBST - {pm-link}

if ($DBC_user['is_guest'])
	$tpl_temp = '<div id="brdwelcome" class="inbox">'."\n\t\t\t".'<p>'.$lang_common['Not logged in'].'</p>'."\n\t\t".'</div>';
else
{
	$tpl_temp = ''."\n\t\t\t".''."\n\t\t\t\t".'user_'.$DBC_user['id'].''."\n\t\t\t\t".'';
}

$tpl_main = str_replace('{profile-link}', $tpl_temp, $tpl_main, $tpl_login);
// END SUBST - {profile-link}


if ($DBC_user['is_guest'])
	$tpl_temp = '<div id="brdwelcome" class="inbox">'."\n\t\t\t".'<p>'.$lang_common['Not logged in'].'</p>'."\n\t\t".'</div>';
else
{
	$tpl_temp = ''."\n\t\t\t".''."\n\t\t\t\t".'posts_uid'.$DBC_user['id'].''."\n\t\t\t\t".'';
}

$tpl_main = str_replace('{user_posts}', $tpl_temp, $tpl_main, $tpl_login);
// END SUBST - {user_posts}

// START SUBST - {login-name}
if ($DBC_user['is_guest'])
	$tpl_temp = ''."\n\t\t\t".'<a href="'.$DBC_config['o_base_url'].'/login">'.$lang_common['Not logged in'].'</a>'."\n\t\t".'';
else
{
	$tpl_temp = ''."\n\t\t\t".''."\n\t\t\t\t".'<strong><a href="user_'.$DBC_user['id'].'">'.DBC_htmlspecialchars($DBC_user['username']).'</a></strong>'."\n\t\t\t\t".'';
}

$tpl_main = str_replace('{login-name}', $tpl_temp, $tpl_main, $tpl_login);
// END SUBST - {login-name}

// START SUBST - {last_visit}
if ($DBC_user['is_guest'])
	$tpl_temp = ''."\n\t\t\t".''."\n\t\t".'';
else
{
	$tpl_temp = ''."\n\t\t\t".''."\n\t\t\t\t".''."\n\t\t\t\t".'<span>'.sprintf($lang_common['Last visit'], format_time($DBC_user['last_visit'])).'</span>';
}

$tpl_main = str_replace('{last_visit}', $tpl_temp, $tpl_main, $tpl_login);
// END SUBST - {last_visit}



// START SUBST - {announcement}
if ($DBC_config['o_announcement'] == '1')
{
	ob_start();

?>
		<div class="annn" style=" margin-bottom: 16px;">
			<span class="ann_t"><?php echo $lang_common['Announcement'] ?></span><div class="ann"><?php echo $DBC_config['o_announcement_message'] ?></div>
		</div>
<?php

	$tpl_temp = trim(ob_get_contents());
	$tpl_main = str_replace('{DBC_announcement}', $tpl_temp, $tpl_main);
	ob_end_clean();
}
else
	$tpl_main = str_replace('{announcement}', '', $tpl_main);
// END SUBST - {announcement}


// START SUBST - {DBC_banner}
if ($DBC_config['o_banner'] == '1')
{
	ob_start();

?>
			<div class="usercontent_bann"><?php echo $DBC_config['o_banner_message'] ?></div>
<?php

	$tpl_temp = trim(ob_get_contents());
	$tpl_main = str_replace('{DBC_banner}', $tpl_temp, $tpl_main);
	ob_end_clean();
}
else
	$tpl_main = str_replace('{DBC_banner}', '', $tpl_main);
// END SUBST - {DBC_banner}


// START SUBST - {DBC_main}
ob_start();

define('DBC_HEADER', 1);